package com.cash.app.ui.auth

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cash.app.base.BaseViewModel
import com.cash.app.manager.AccountInfoManager
import com.cash.app.manager.api.GlobalAPIService
import com.cash.app.manager.model.AccountDetailResponse
import com.cash.app.net.NetRequestExecutor
import com.cash.app.net.RetrofitClient
import com.cash.app.ui.auth.api.AuthAPIService
import com.cash.app.ui.auth.model.MetaRsp

class AuthACViewModel : BaseViewModel() {

    private val authAPIService by lazy {
        RetrofitClient.createService(AuthAPIService::class.java)
    }

    private val globalAPIService by lazy {
        RetrofitClient.createService(GlobalAPIService::class.java)
    }

    private val _metaData = MutableLiveData<MetaRsp>()
    val metaData: LiveData<MetaRsp> = _metaData

    private val _accountDetail = MutableLiveData<AccountDetailResponse>()
    val accountDetail: LiveData<AccountDetailResponse> = _accountDetail

    fun getMetaData() {
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                authAPIService.getMetaData()
            }
        }, onSuccess = { response ->
            response?.let {
                _metaData.value = it
            }
        })
    }

    fun getAccountDetail() {
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                globalAPIService.getAccountDetail()
            }
        }, onSuccess = { response ->
            response?.let {
                _accountDetail.value = it
                AccountInfoManager.updateAccountInfo(it)
            }
        })
    }
} 